package com.douma.tool.dto;

/**
 * @Description 数据表对应DTO生成器
 * @Author haoxijun
 * @Date 2019/12/9
 * @Time 17:29
 */
public class DtoGenerater {

    public static void main(String[] args) {

        String inputString = getOutStrings();
        String[] inputStrings = inputString.split("\n");
        for (String string : inputStrings) {

            String property = string.split("` ")[0];
            String[] propertys = property.split("_");
            String field = "";
            for (String s : propertys) {
                if ("".equals(field)) {
                    field = s;
                } else {
                    field = field + upperCase(s);
                }
            }
            field = field.replaceAll("`", "");

            String[] remarkString = string.split("COMMENT");
            String remark = remarkString[remarkString.length-1];
            remark = remark.replaceAll(" '","");
            remark = remark.replaceAll("',","");

            System.out.println("    /**");
            System.out.println("     * "+remark+"");
            System.out.println("     */");
            System.out.println("    private String "+field+";");
            System.out.println("");
        }

    }

    public static String getOutStrings() {
        String inputString =
                "`id` bigint(20) NOT NULL COMMENT '主键id',\n" +
                        "`house_id` varchar(20) NOT NULL COMMENT '房屋id',\n" +
                        "`house_type` int(4) NOT NULL COMMENT '；类型(1:电梯房;2-非电梯房;3-别墅;4-门店;5-厂房;6-仓库)',\n" +
                        "`house_name` varchar(100) NOT NULL COMMENT '房屋名称',\n" +
                        "`village_id` varchar(20) NOT NULL COMMENT '小区id',\n" +
                        "`number` int(4) NOT NULL COMMENT '号',\n" +
                        "`floor` int(4) NOT NULL COMMENT '楼',\n" +
                        "`room` int(4) NOT NULL COMMENT '室',\n" +
                        "`room_count` int(4) DEFAULT NULL COMMENT '室数',\n" +
                        "`sitting_count` int(4) DEFAULT NULL COMMENT '厅数',\n" +
                        "`toilet_count` int(4) DEFAULT NULL COMMENT '卫数',\n" +
                        "`kitchen_count` int(4) DEFAULT NULL COMMENT '厨数',\n" +
                        "`balcony_count` int(4) DEFAULT NULL COMMENT '阳台数',\n" +
                        "`loft_count` int(4) DEFAULT NULL COMMENT '阁楼数',\n" +
                        "`garden_count` int(4) DEFAULT NULL COMMENT '花园数',\n" +
                        "`area` decimal(16,4) NOT NULL COMMENT '面积(平米)',\n" +
                        "`price` decimal(16,4) NOT NULL COMMENT '总价(万元)',\n" +
                        "`owner_id` varchar(100) NOT NULL COMMENT '业主id',\n" +
                        "`lock_status` int(4) NOT NULL COMMENT '数据状态(1:公开;2:权限内可见;3:本人可见)',\n" +
                        "`other_info` text COMMENT '其他信息',";

        return inputString;
    }

    public static String upperCase(String str) {
        return str.substring(0, 1).toUpperCase() + str.substring(1);
    }
}
